# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-06-06
# @File : 5_hook.py

import frida
import sys

rdev = frida.get_remote_device()
# Application(identifier="tv.danmaku.bili", name="哔哩哔哩", pid=20650, parameters={})
session = rdev.attach("哔哩哔哩")

scr = """
Java.perform(function () {

    var b = Java.use("t3.a.i.a.a.a.b");

    var ByteString = Java.use("com.android.okhttp.okio.ByteString");


    b.a.implementation = function(str){
        console.log("请求来了");
        console.log("str=",str);
        var res = this.a(str);
        console.log("字节数组=",res);
        console.log("字节数组=",ByteString.of(res).hex());

        return res;
    };

});
"""

script = session.create_script(scr)


def on_message(message, data):
    print(message, data)


script.on("message", on_message)

script.load()
sys.stdin.read()
